package zozopo.attendance;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import zozopo.attendance.operations.LeaveOS;
import zozopo.attendance.operations.LeaveTB;
import zozopo.attendance.operations.OperatorAttendanceOS;
import zozopo.attendance.operations.OperatorAttendanceTB;
import zozopo.background.operator.operations.OperatorTB;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class PreAddLeaveAction extends ActionSupport implements Action,SessionAware{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	


	//传出参数
	
	private OperatorAttendanceTB operatorOfAttendance;
	private OperatorTB operator;
	private String date;
	private String begin_leave;
	private String end_leave;
	
	
	
	
	private Map<Object, Object> session;
	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}
	public String execute(){
		
		String temp_str="";
	    
	    //最后的aa表示“上午”或“下午”    HH表示24小时制    如果换成hh表示12小时制
	    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	    
	    Calendar calendar =Calendar.getInstance();
	    calendar.add(Calendar.DAY_OF_YEAR, 1);
	    
	    Date dt=calendar.getTime();
	    
	    temp_str=sdf.format(dt);

	    date = temp_str;
		
		
		return SUCCESS;
		
	}

	public void validate() {
		//权限处理
	
		operator = (OperatorTB)session.get("operatorInfo"); 
	
		if(operator == null){
			addFieldError("errormessage",getText("operator.timeoutornotlogin"));
			return ; 
		} 
		//用户权限
		
		OperatorAttendanceOS operatorOfAttendanceOS = new OperatorAttendanceOS();
		LeaveOS leaveOS = new LeaveOS(operatorOfAttendanceOS.getConn());
		if(!operatorOfAttendanceOS.isExist(operator.getId_operator())){
			operatorOfAttendanceOS.releaseConnection();
			addFieldError("errormessage","用户未加入考勤系统无法请假!请联系管理人员.!!");
			return ; 
		}
		operatorOfAttendance = operatorOfAttendanceOS.getInfoByOperatorid(operator.getId_operator());
		
		begin_leave = operatorOfAttendance.getWorkhours_operator();
		end_leave = operatorOfAttendance.getOffhours_operator();
		
	
		
		operatorOfAttendanceOS.releaseConnection();
	}
	public OperatorAttendanceTB getOperatorOfAttendance() {
		return operatorOfAttendance;
	}
	public void setOperatorOfAttendance(OperatorAttendanceTB operatorOfAttendance) {
		this.operatorOfAttendance = operatorOfAttendance;
	}
	public OperatorTB getOperator() {
		return operator;
	}
	public void setOperator(OperatorTB operator) {
		this.operator = operator;
	}
	
	public String getDate() {
		return date;
	}
	public void setDate(String date) {
		this.date = date;
	}
	public String getBegin_leave() {
		return begin_leave;
	}
	public void setBegin_leave(String begin_leave) {
		this.begin_leave = begin_leave;
	}
	public String getEnd_leave() {
		return end_leave;
	}
	public void setEnd_leave(String end_leave) {
		this.end_leave = end_leave;
	}
	
	

}
